<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>${tabTitle}</title>
    <jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <form id="ins_cfg_info_edit_form_xyfl">
                <div class="fieldset1 tabel_col clearFix">
                    <div class="fieldBox col_33">
                        <div class="label">机构名称</div>
                        <div class="field">
                            <span name="fundRasInsNm" id="fundRasInsNm">${fundRasInsNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">客户名称</div>
                        <div class="field">
                            <span >${cstNm}</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">身份证号码</div>
                        <div class="field">
                            <span >${certNo}</span>
                        </div>
                    </div>

                    <div class="fieldBox col_33">
                        <div class="label">开户银行</div>
                        <div class="field">
                            <select name="bkCd" id="bkCd" value="${bkCd}" validate="{required:true}">
                                <c:if test="${bkCd == null || bkCd == ''}">
                                    <option value="" selected="selected">--请选择--</option>
                                </c:if>
                                <c:if test="${bkCd != null && bkCd != ''}">
                                    <option value="">--请选择--</option>
                                </c:if>
                                <c:forEach items="${bankList}" var="item">
                                    <c:if test="${item.key == bkCd}">
                                        <option value="${item.key}" selected="selected">${item.value}</option>
                                    </c:if>
                                    <c:if test="${item.key != bkCd}">
                                        <option value="${item.key}">${item.value}</option>
                                    </c:if>
                                </c:forEach>
                            </select>
                            <span class="requiredSymbol" id="money">* 单笔限额：${money}元</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">银行账号</div>
                        <div class="field">
                            <input name="accNo" id="accNo" type="text" class="ui-textbox" value="${accNo}" validate="{required:true,number:true, maxlength:22, minlength:15}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">预留手机号</div>
                        <div class="field">
                            <input name="mp" id="mp" type="text" class="ui-textbox" value="${mp}" validate="{number:true, maxlength:11, minlength:11,required:true}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33 ">
                        <div class="label">身份证有效期 (止)</div>
                        <div class="field">
                            <input name="certValidEDt" id="certValidEDt" type="text" class="ui-datepicker" value="${certValidEDt}" validate="{required:true}">
                            <div><input type="checkbox" name="checkOne" id="checkOne"  <c:if test="${certValidEDt=='2099-12-31'}">checked</c:if> value="长期" onchange="enduring(this)">长期</div>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">短信验证码</div>
                        <div class="field">
                            <input name="verificationCode" id="verificationCode" type="text" class="ui-textbox" value="${verificationCode}" validate="{number:true, maxlength:6, minlength:4}">
                            <span class="requiredSymbol">*</span>
                            <span id="sendVerifyCode" class= "sq-button sq-button-round" onclick="getPhoneCode(this)">获取验证码</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">月收入</div>
                        <div class="field">
                            <input name="monthlyIncome" id="monthlyIncome" type="text" class="ui-textbox" value="${monthlyIncome}" validate="{number:true, maxlength:20, minlength:1,required:true}">
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>
                    <div class="fieldBox col_33">
                        <div class="label">民族</div>
                        <div class="field">
                            <select name="nation" id="nation" value="${nation}" validate="{required:true}">
                                <c:if test="${nation == null || nation == ''}">
                                    <option value="" selected="selected">--请选择--</option>
                                </c:if>
                                <c:if test="${nation != null && nation != ''}">
                                    <option value="">--请选择--</option>
                                </c:if>
                                <c:forEach items="${nationList}" var="item">
                                    <c:if test="${item.value == nation}">
                                        <option value="${item.value}" selected="selected">${item.value}</option>
                                    </c:if>
                                    <c:if test="${item.value != nation}">
                                        <option value="${item.value}">${item.value}</option>
                                    </c:if>
                                </c:forEach>
                            </select>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>


                    <div class="fieldBox col_50">
                        <div class="label">户籍地省市</div>
                        <div class="field">
                            <jsp:include page="../../system/sysRegion/regionAud.jsp" flush="true">
                                <jsp:param name="regionShowAudLvl"  value="2"/>
                            </jsp:include>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>

                    <div class="fieldBox col_50">
                        <div class="label">现居住地省市</div>
                        <div class="field">
                            <jsp:include page="../../system/sysRegion/region.jsp" flush="true">
                                <jsp:param name="regionShowLvl"  value="2"/>
                            </jsp:include>
                            <span class="requiredSymbol">*</span>
                        </div>
                    </div>

                    <!-- hide data -->
                    <div class="fieldBox col_100" style="display: none;">
                        <div class="field">
                            <input name="prjId" id="prjId" type="text" class="ui-textbox" value="${prjId}">
                            <input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
                            <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="${cstNm}">
                            <input name="certNo" id="certNo" type="text" class="ui-textbox" value="${certNo}">
                            <input name="cstAccInfoId" id="cstAccInfoId" type="text" class="ui-textbox" value="${cstAccInfoId}">
                            <input name="fundRasInsId" id=fundRasInsId type="text" class="ui-textbox" value="${fundRasInsId}">
                            <input name="accResCd" id=accResCd type="text" class="ui-textbox" value="${accResCd}">
                        </div>
                    </div>
                </div>
                <div id="saveInsCfgDiv" class="btnsBox">
                    <sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjBscInfo" pInstId="${pInstId}">
                        <span id="saveInsCfg" class="sq-button sq-button-round" onclick="return saveInfo();">保存</span>
                    </sys:FlowFrmAth>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">

    var detailFlag = '${detailFlag}';
    var updateFlag = '${updateFlag}';
    var fromCAFlag = '${fromCAFlag}';
    var fromCMFlag = '${fromCMFlag}';
    var singleQuotaMap = '${singleQuotaMap}';

    $(function () {
        initData();
        $("#bkCd").change(function(){
            var bankNo = $("#bkCd").val();
            var money = singleQuotaMap[bankNo+""];
            $("#money").html(money ? money : "");
        });
        enduring();
    });

    function initData() {
        $("#ins_cfg_info_edit_form_xyfl").ligerForm({
            validate: true
        });
        disabledInput();
        disabledInput1();
        setRgnProvCdUpdataValue('${rgnPrCd}');
        setRgnCityCdUpdataValue('${rgnCyCd}');
        setRgnProvCdUpdataValue2('${rgnPrCd2}');
        setRgnCityCdUpdataValue2('${rgnCyCd2}');
        // enableFields();
    }
    /*
        *获取手机验证码
        */
    function getPhoneCode(obj) {
        if (paramsVerify()){
            //还款账户名
            var cstNm = $("#cstNm").val();
            //还款账户号
            var accNo = $("#accNo").val();
            //还款开户行
            var bkCd = $("#bkCd").val();
            //还款开户行
            var bkNm = liger.get("bkCd").selectedText;

            //还款证件号
            var certNo = $("#certNo").val();
            var prjId = $("#prjId").val();
            var cstId = $("#cstId").val();
            var insId = $("#fundRasInsId").val();

            //手机号
            var mp = $("#mp").val();
            $.ajax({
                url:"/institution/xyfl/verifycode.do",
                data:{
                    cstNm:cstNm,
                    accNo:accNo,
                    certNo:certNo,
                    mp:mp,
                    prjId:prjId,
                    cstId:cstId,
                    bkCd:bkCd,
                    bkNm:bkNm,
                    insId:insId
                },
                dataType:"json",
                type:"post",
                async:false,
                cache:false,
                success: function (msg) {
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        settime(obj);
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                },
                error:function () {
                    UIUtils.alertError("验证码发送失败");
                }
            });
        }
    }

    //电话号码校验
    function isPhoneNumber() {
        var phone = $("#mp").val();
        var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
        if (!reg.test(phone)){
            UIUtils.alertError("请输入有效手机号");
            return false;
        }else {
            return true;
        }
    }
    var countdown = 60;
    function settime(obj) { //发送验证码倒计时
        if (countdown == 0) {
            $(obj).removeClass("disabledBtn")
            $(obj).text("获取验证码");
            countdown = 60;
            return;
        } else {
            $(obj).addClass("disabledBtn")
            $(obj).text("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function () {
            settime($(obj))
        }, 1000)
    }
    //必要参数校验
    function paramsVerify() {
        //还款账户名
        var accountName = $("#cstNm").val();
        //还款账户号
        var accountNo = $("#accNo").val();
        //还款证件号
        var certId = $("#certNo").val();
        //手机号
        var reservePhone = $("#mp").val();
        if (!accountName){UIUtils.alertError("客户名称不能为空"); return false;}
        if (!accountNo){UIUtils.alertError("银行账号不能为空");return false;}
        if (!certId){UIUtils.alertError("身份证号码不能为空");return false;}
        if (!reservePhone){UIUtils.alertError("预留手机号不能为空不能为空");return false;}
        return true;

    }
    //验证码倒计时60s
    var countDown = 60;
    function settime(obj) { //发送验证码倒计时
        if (countdown == 0) {
            $(obj).removeClass("disabledBtn");
            $(obj).text("获取验证码");
            countdown = 60;
            return;
        } else {
            $(obj).addClass("disabledBtn");
            $(obj).text("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function () {
            settime($(obj))
        }, 1000)
    }

    function enableFields() {
        if (null != fromCAFlag && "true" == fromCAFlag) {
            liger.get("rgnProvCd2").setEnabled();
            liger.get("rgnCityCd2").setEnabled();
            $("#saveInsCfgDiv").show();
        }
        if (null != fromCMFlag && "true" == fromCMFlag) {
            liger.get("rgnProvCd2").setEnabled();
            liger.get("rgnCityCd2").setEnabled();
            $("#saveInsCfgDiv").show();
        }
    }

    //
    function disabledInput() {
        var accResCd = $("#accResCd").val();
        if (accResCd == "0000"){
            liger.get("bkCd").setDisabled();//银行编码
            liger.get("accNo").setDisabled();//银行账号
            liger.get("mp").setDisabled();//手机
            liger.get("monthlyIncome").setDisabled();//月收入
            liger.get("nation").setDisabled();//民族
            liger.get("rgnProvCd2").setDisabled();//户籍地省
            liger.get("rgnCityCd2").setDisabled();//户籍地市
            liger.get("rgnProvCd").setDisabled();//居住地市
            liger.get("rgnCityCd").setDisabled();//居住地市
            liger.get("verificationCode").setDisabled();//短信验证码
            liger.get("certValidEDt").setDisabled();
            $("#saveInsCfgDiv").hide();//保存
            $("#sendVerifyCode").hide();//获取验证码
        }
        // if(accResCd == "0000") {
        //
        // }
    }
    function disabledInput1() {
        if (detailFlag == "true"){
            liger.get("bkCd").setDisabled();//银行编码
            liger.get("accNo").setDisabled();//银行账号
            liger.get("mp").setDisabled();//手机
            liger.get("monthlyIncome").setDisabled();//月收入
            liger.get("nation").setDisabled();//民族
            liger.get("rgnProvCd2").setDisabled();//户籍地省
            liger.get("rgnCityCd2").setDisabled();//户籍地市
            liger.get("rgnProvCd").setDisabled();//居住地市
            liger.get("rgnCityCd").setDisabled();//居住地市
            liger.get("verificationCode").setDisabled();//短信验证码
            liger.get("certValidEDt").setDisabled();
            $("#saveInsCfgDiv").hide();//保存
            $("#sendVerifyCode").hide();//获取验证码
        }
    }

    // 保存项目客户信息，后面弹出准入验证的资料确认页
    function saveInfo() {
        debugger;
        var ligerForm = liger.get("ins_cfg_info_edit_form_xyfl");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
            //验证不通过，不执行以下代码
            return false;
        }
        var data = ligerForm.getData();
        data["bkCd"] = liger.get("bkCd").selectedValue;
        data["bkNm"] = liger.get("bkCd").selectedText;
        data["accNo"] =  $("#accNo").val();
        data["mp"] = $("#mp").val();
        data["certNo"] = $("#certNo").val();
        data["accResCd"] = $("#accResCd").val();
        data["id"] = $("#cstAccInfoId").val();//项目id
        data["prjId"] = $("#prjId").val();
        data["insCode"] = 'xyfl';
        data["cstId"] = $("#cstId").val();
        data["phoneCode"] = $("#verificationCode").val();
        data["nation"] = $("#nation").val();
        data["monthlyIncome"] = $("#monthlyIncome").val();
        data["fundRasInsId"] = $("#fundRasInsId").val();
        data["rgnPrCd2"] = getRgnProvCd2();//户籍地省
        data["rgnCyCd2"] = getRgnCityCd2();//户籍地市
        data["rgnPrCd"] = getRgnProvCd();//居住地省
        data["rgnCyCd"] = getRgnCityCd();//居住地市
        data["certValidEDt"] = $("#certValidEDt").val();
        data["insId"] = $("#fundRasInsId").val();

        var rgnPrCd2 = getRgnProvCd2();//居住地省
        if (!rgnPrCd2){
            UIUtils.alertErrorHold1("户籍地省不能为空");
            return ;
        }
        var rgnCyCd2 = getRgnCityCd2();//居住地市
        if (!rgnCyCd2){
            UIUtils.alertErrorHold1("户籍地市不能为空");
            return ;
        }
        var rgnPrCd = getRgnProvCd();//户籍地省
        if (!rgnPrCd){
            UIUtils.alertErrorHold1("居住省不能为空");

            return ;
        }
        var rgnCyCd = getRgnCityCd();//户籍地市
        if (!rgnCyCd){
            UIUtils.alertErrorHold1("居住地市不能为空");
            return ;
        }
        if (null == certValidEDt) {
            data["certValidEDt"] = $("#certValidEDt").val();//身份证截止日期
        } else {
            data["certValidEDt"] = certValidEDt;
        }
        if (!$("#certValidEDt").val()){
            UIUtils.alertErrorHold1("身份证截止日期不能为空");
            return ;
        }
        var accResCd = $("#accResCd").val();
        var phoneCode = $("#verificationCode").val();
        if (!accResCd == "0000" && !phoneCode){
            UIUtils.alertErrorHold1("验证码不能为空");
            return ;
        }
        var url = '<%=path%>/institution/xyfl/savexyfl.do';
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    disabledInput();
                    UIUtils.alertSuccessHold1(msg.info);
                } else {
                    UIUtils.alertErrorHold1(msg.info);
                }
            },
            error:function (msg) {
                UIUtils.alertErrorHold1("系统错误");
            }
        });
    }

    //选择长期置灰时间控件
    function enduring(checkbox) {
        if ($("#checkOne").is(':checked')){
            $("#certValidEDt").hide();
            $("#certValidEDt").val("2099-12-31");
        } else {
            $("#certValidEDt").show();
            certValidEDt = null;
        }
    }

</script>

</body>
</html>